<?php

namespace App\Http\Controllers\Web;

use Illuminate\Http\Request;
use App\Http\Controllers\Web\BaseController;
use App\Http\Model\Services;

class ServicesController extends BaseController
{
    /**
     * 服务列表接口
     * @return void
     */
    public function serviceList()
    {
        $service_info = Services::all();
        return parent::success($service_info);
    }


    /**
     * 添加服务接口
     * @param Request $request
     * @return void
     */
    public function AddService(Request $request)
    {
        $service_id = intval($request->input('id', 0));
        $service_info = [];
        if ($service_id) {
            $service_info = Services::where('id', $service_id)->first();
        }
        if ($request->isMethod('post')) {
            $service_id = intval($request->input('id', 0));
            $service_name = trim($request->input('serivce_name', ''));
            if (!$service_name) {
                return parent::fail('参数有误');
            }
            $service_arr = Services::where('id', $service_id)->first();
            if (isset($service_arr->id)) {
                $service_info = $service_arr;
            } else {
                $service_info = new Services();
            }
            $service_info->serivce_name = $service_name;
            $service_info->save();
            return parent::success([], '添加成功');
        }
        return parent::success($service_info);
    }
}
